const express = require('express');
const router = express.Router();
const db = require("../../../../util/dbConfig/dbConfig")

router.delete('/',async(req,res) => {
    if(req.session.userInfo.admin !== 1){
        return res.send({
            code: 3,
            msg: '非管理员不可访问'
        })
    }
    let {sheepId} = req.body
    if(!sheepId){
        return res.send({
            code: 1,
            msg: '参数错误'
        })
    }
    try{
        let deleteSql = `delete from sheep where ID=?`
        let deleteSqlArr = [sheepId]
        let result = await db.SySqlConnect(deleteSql,deleteSqlArr)
        // console.log(result['affectedRows']);
        if(result['affectedRows'] !== 1){
            return res.send({
                code: 2,
                msg: '删除失败'
            })
        }
        return res.send({
            code: 0,
            msg: '删除成功'
        })
    }catch (e) {
        console.log(e);
        return res.send({
            code: 4,
            msg: '服务器错误，请稍后再试'
        })
    }
})

module.exports = router
